﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace ScreenMonitor.Common.Objects
{
    public sealed class SignRequestObject
    {
        private static object StaticLockObj = new object();
        private object LockObj = new object();

        public int SignLimitTime { get; set; }
        public bool IsLockScreen { get; set; }
        public byte[] ToByte()
        {
            lock (LockObj)
            {
                MemoryStream stream = new MemoryStream();
                BinaryWriter bw = new BinaryWriter(stream);
                bw.Write(SignLimitTime);
                bw.Write(IsLockScreen);
                bw.Flush();
                byte[] r = stream.ToArray();
                return r;
            }
        }
        public static SignRequestObject FromByte(byte[] Data)
        {
            lock (StaticLockObj)
            {
                MemoryStream stream = new MemoryStream(Data);
                BinaryReader br = new BinaryReader(stream);
                SignRequestObject obj = new SignRequestObject();
                obj.SignLimitTime = br.ReadInt32();
                obj.IsLockScreen = br.ReadBoolean();
                br.Close();
                return obj;
            }
        }


    }
}
